/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package deitel.composicion;
/**
 *
 * @author Kelly Ruiz
 */
public class Fecha {
    
    public int mes;
    public int dia;
    public int anio;
    
    public Fecha(int mes, int dia, int anio){
     
            this.mes = comprobarMes(mes);
            this.anio = anio;
            this.dia = comprobarDia(dia); 
   
    }
    
    public Fecha(Fecha F){
        this.dia = F.dia;
        this.mes = F.mes;
        this.anio = F.anio;
        
    }
    
    public int comprobarMes(int m){
        
        if (m > 0 && m <= 12)
        {
            return m;
        }else{
            return -1;
        }
    }
    
    public int comprobarDia(int d)
    {
        //int a;
        //a = comprobarMes(mes);
        if (comprobarMes(mes) != -1){
            if (mes == 2){
                if (comprobarBiciesto(anio)){
                    if (d > 0 && d <= 28){
                        return d;
                    }else{
                        return -1;
                    }
                }else{
                    if (d > 0 && d<= 29){
                        return d;
                    }else{
                        return -1;
                    }
                    
                }
            }else{
                if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12){
                    if (d>0 && d<= 31){
                        return d;
                    }else{
                        return -1;
                    }
                }else{
                    if (d>0 && d<=30){
                        return d;
                    }else{
                        return -1;
                    }
                }
            }
        }else{
            return -1;
        }
    }
    
    public boolean comprobarBiciesto(int an)
    {
        
        if (an % 4 == 0 && (an % 100 != 0 || an % 400 == 0)){
            return true;
        }else{
            return false;
        }
 
    }
    
    /*public static void main(String[] args) {
        Fecha f = new Fecha(01,5,2012);
        
        System.out.printf("Imprimir Fecha: %d/%d/%d ", f.dia,f.mes,f.anio );
        //System.out.pr
    }*/
}
